﻿using Iot.AlarmDispose.Database.Entities;

namespace Iot.AlarmDispose;

/// <summary>
///     报警工厂接口  使用报警状态和报警分类创建报警历史记录
/// </summary>
/// <typeparam name="TAlertClassify"></typeparam>
/// <typeparam name="TAlertsHistory"></typeparam>
public interface IAlertsFactory<TAlertClassify, out TAlertsHistory>
    where TAlertClassify : class, IAlertClassify
    where TAlertsHistory : class, IAlertsHistory<TAlertClassify>
{
    /// <summary>
    ///     创建TAlertsHistory对象
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    TAlertsHistory Create(SwitchData<TAlertClassify> data);
}

public class DefaultAlertsFactory<TAlertClassify, TAlertsHistory> : IAlertsFactory<TAlertClassify, TAlertsHistory>
    where TAlertClassify : class, IAlertClassify
    where TAlertsHistory : class, IAlertsHistory<TAlertClassify>, new()
{
    public TAlertsHistory Create(SwitchData<TAlertClassify> data)
    {
        return new TAlertsHistory
        {
            StartTime = data.SwitchInt.TimeStamp,
            AlertsInformation = data.AlertClassify
        };
    }
}